{include file='header'/}
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <table id="admin_table" lay-filter="admin_table"></table>
    </div>
</div>
<script type="text/html" id="add_toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md"
            data-open="<?php echo url('auth_group/add');?>"
            data-title="添加角色组">
        <i class="layui-icon layui-icon-add-1"></i>
        添加角色组
    </button>
</script>


<script type="text/html" id="statusTpl">
    {{#  if(d.status =='normal'){ }}
    <span class="layui-badge layui-bg-green"> 已启用 </span>
    {{#  } else { }}
    <span class="layui-badge layui-bg-danger"> 已禁用 </span>
    {{#  } }}
</script>

<script type="text/html" id="barDemo">
    {{#  if(d.id !='1'){ }}
    <button class="pear-btn pear-btn-primary pear-btn-sm" title="编辑"
            data-open="<?php echo url('auth_group/edit');?>?id={{d.id}}"
            data-title="编辑">
        <i class="layui-icon layui-icon-edit"></i>
    </button>
    <button class="pear-btn pear-btn-danger pear-btn-sm" title="删除"
            data-delete="<?php echo url('auth_group/delete');?>?id={{d.id}}"
            data-title="您确定要删除吗？" data-reload="2">
        <i class="layui-icon layui-icon-delete"></i>
    </button>
    {{#  } }}
</script>

{include file='footer'/}
<script>
  layui.use(['table', 'jquery'], function () {
    var $ = layui.jquery;
    var table = layui.table;
    table.render({
      elem: '#admin_table'
      , toolbar: '#add_toolbar'
      , defaultToolbar: [{
        layEvent: 'refresh',
        icon: 'layui-icon-refresh',
        title: '刷新'
      }, 'filter', 'exports']
      , method: 'get'
      , url: "<?php echo url('auth_group/index');?>"
      , parseData: function (res) {
        return {
          "code": 0,
          "msg": res.msg,
          "count": res.count,
          "data": res.data
        };
      }
      , cellMinWidth: 100
      , cols: [[
        {field: 'id', title: 'ID', width: 60, align: 'center', sort: true}
        , {field: 'name', title: '角色名'}
        , {field: 'status', title: '状态', templet: '#statusTpl', align: 'center'}
        , {field: 'createtime', title: '添加时间', align: 'center'}
        , {fixed: 'right', title: '操作', toolbar: '#barDemo', align: 'center', width: 130}
      ]]
      , id: 'testReload'
      , page: true
      , limit: 10
    });
    var $ = layui.$, active = {
      reload: function () {
        //执行重载
        table.reload('testReload', {
          page: {curr: 1}
        });
      }
    };
    //监听排序
    table.on('sort(admin_table)', function (obj) {
      table.reload('testReload', {
        initSort: obj
        , where: {
          field: obj.field
          , order: obj.type
        }
      });
    });

    $('.hui-form-search .layui-btn').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    $('.hui-form-search .reset').on('click', function () {
      window.location.reload();
    });

    //监听行工具事件
    table.on('toolbar(admin_table)', function (obj) {
      if (obj.event === 'refresh') {
        table.reload('testReload');
      }
    });
  });
</script>
</body>
</html>
